<template>
	<div>
		<!--搜索表单-->
		<div class="common-seach-wrap">
			<el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
				<el-form-item label="起始时间">
					<div class="block">
						<el-date-picker v-model="formInline.search_time" type="daterange" value-format="yyyy-MM-dd"
							range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
					</div>
				</el-form-item>
				<el-form-item label="自提点">
					<el-select size="small" v-model="formInline.extract_store_id" filterable placeholder="请选择">
						<el-option label="全部" value=""></el-option>
						<el-option v-for="(item, index) in shops" :key="item.store_id" :label="item.store_name"
							:value="item.store_id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="商品名称">
					<el-input v-model="formInline.goodsName" placeholder="请输入商品名称" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
					<el-form-item><el-button size="small" type="success" @click="onExport">导出</el-button></el-form-item>
				</el-form-item>
			</el-form>
		</div>

		<!--内容-->
		<div class="product-content">
			<div class="table-wrap">
				<el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
					<el-table-column prop="product_name" label="商品名称"></el-table-column>
					<el-table-column prop="product_image" label="商品图">
						<template slot-scope="scope">
							<img :src="scope.row.product_image" width="30px" height="30px" />
						</template>
					</el-table-column>
					<el-table-column prop="order" label="商品数量">
						<template slot-scope="scope">
							<div v-for="(item, index) in scope.row.order" :key="index">
								<!-- <span>{{ item.spec }}</span> -->
								<span style="color: #ff0000;">{{ item.number }}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column prop="moneys" label="合计金额 "></el-table-column>
				</el-table>
			</div>

			<!--分页-->
			<div class="pagination">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
					:current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
					:total="totalDataNumber"></el-pagination>
			</div>
		</div>
	</div>
</template>

<script>
	import StatisticsApi from '@/api/statistics.js';
	import OrderApi from '@/api/order.js';
	import qs from 'qs';
	export default {
		data() {
			return {
				/*是否加载完成*/
				loading: true,
				/*列表数据*/
				tableData: [],
				/*一页多少条*/
				pageSize: 20,
				/*一共多少条数据*/
				totalDataNumber: 0,
				/*当前是第几页*/
				curPage: 1,
				/*横向表单数据模型*/
				formInline: {
					search_time: [],
					goodsName: '',
					extract_store_id: ''
				},
				/*配送方式*/
				orderStatus: [
					//{bankCode: 'ALIPAY', bankName: '支付宝账户'},
					//{bankCode: 'WECHAT', bankName: '微信账户'},
					{
						name: '待发货',
						value: '10'
					},
					{
						name: '待收货',
						value: '15'
					},
					{
						name: '已收货',
						value: '20'
					}
				],
				shops: []
			}
		},
		created() {
			/*获取列表*/
			this.getTableList();
			this.getData()
		},
		methods: {
			getData() {
				OrderApi.orderlist({}, true)
					.then(res => {
						this.shops = res.data.shops
					})
			},
			onExport: function() {
				let baseUrl = window.location.protocol + '//' + window.location.host;
				window.location.href = baseUrl + '/index.php/shop/statistics.sales/orderCountExcel?' + qs.stringify(
					this.searchForm);
			},
			/*选择第几页*/
			handleCurrentChange(val) {
				let self = this;
				self.curPage = val;
				self.loading = true;
				self.getTableList();
			},

			/*每页多少条*/
			handleSizeChange(val) {
				this.curPage = 1;
				this.pageSize = val;
				this.getTableList();
			},

			/*获取列表*/
			getTableList() {
				let self = this;
				let Params = self.formInline;
				Params.page = self.curPage;
				Params.list_rows = self.pageSize;
				StatisticsApi.orderCount(Params, true)
					.then(data => {
						self.loading = false;
						self.tableData = data.data.data;
						self.totalDataNumber = data.data.total;
					})
					.catch(error => {
						self.loading = false;
					});
			},
			/*搜索查询*/
			onSubmit() {
				let self = this;
				self.loading = true;
				self.getTableList();
			},
		},
	}
</script>

<style></style>
